## Civcraft: SC Mod Specialized Python Functions
from CvPythonExtensions import *

gc = CyGlobalContext()
localtext = CyTranslator()


def checkAndRemoveEnergy(pUnit, iEnergyAmt):
    """
    Arguments:
        pUnit: The CyUnit object of the unit to check for.
        iEnergyAmt: The amount of energy to check for.

    Returns:
        True if the unit had the energy and it was subtracted.
        False if the unit did not have the energy.

    This takes into consideration both the unit's energy and if the
    unlimited energy cheat is enabled.
    """

    if gc.getPlayer(pUnit.getOwner()).isCheatEnabled(CheatTypes.CHEAT_INFINITE_ENERGY):
        return True
    else:
        if pUnit.currEnergy() < iEnergyAmt:
            return False
        else:
            pUnit.changeEnergy(-1 * iEnergyAmt)
            return True

        
def showNotEnoughEnergyMsg(iPlayer):
    """
    Arguments:
        iPlayer: The player to show the message to

    Returns:
        None

    This will simply display the not enough energy message on a player's screen.
    """

    CyInterface().addMessage(iPlayer, True, 10, # GERIKESTODO: Magic number
                                        localtext.getText("TXT_KEY_NOT_ENOUGH_ENERGY", ()), None, # GERIKESTODO: gc.getCivilizationInfo(gc.getPlayer(iPlayer).getCivilizationType()).getNotEnoughEnergyScript()
                                        InterfaceMessageTypes.MESSAGE_TYPE_INFO, None, gc.getInfoTypeForString("COLOR_NOT_ENOUGH_TEXT"), -1, -1, False, False)

def showNotEnoughHealthMsg(iPlayer):
    """
    Arguments:
        iPlayer: The player to show the message to

    Returns:
        None

    This will simply display the not enough health message on a player's screen.
    """

    CyInterface().addMessage(iPlayer, True, 10, # GERIKESTODO: Magic number
                                        localtext.getText("TXT_KEY_NOT_ENOUGH_HEALTH", ()), None, # GERIKESTODO: gc.getCivilizationInfo(gc.getPlayer(iPlayer).getCivilizationType()).getNotEnoughHealthScript()
                                        InterfaceMessageTypes.MESSAGE_TYPE_INFO, None, gc.getInfoTypeForString("COLOR_NOT_ENOUGH_TEXT"), -1, -1, False, False)

def showNotEnoughMineralsMsg(iPlayer):
    """
    Arguments:
        iPlayer: The player to show the message to

    Returns:
        None

    This will simply display the not enough minerals message on a player's screen.
    """

    CyInterface().addMessage(iPlayer, True, 10, # GERIKESTODO: Magic number
                                        localtext.getText("TXT_KEY_NOT_ENOUGH_MINERALS", ()), None, # GERIKESTODO: gc.getCivilizationInfo(gc.getPlayer(iPlayer).getCivilizationType()).getNotEnoughHealthScript()
                                        InterfaceMessageTypes.MESSAGE_TYPE_INFO, None, gc.getInfoTypeForString("COLOR_NOT_ENOUGH_TEXT"), -1, -1, False, False)


def getEnergyUsageString(iEnergy, bNewLine = True):
    if bNewLine:
        return u"%d %c\n" %(iEnergy, CyGame().getSymbolID(FontSymbols.POWER_CHAR))
    else:
        return u"%d %c" %(iEnergy, CyGame().getSymbolID(FontSymbols.POWER_CHAR))


def isHallucination(pUnit):
    iHallucinationUnitAttachment = gc.getInfoTypeForString("UNIT_ATTACHMENT_HALLUCINATION")
    return pUnit.getTotalNumUnitAttachments(iHallucinationUnitAttachment) > 0
